#include "Connection.h"
#include "ConnectionPool.h"
#include <cstdio>
#include <ctime>

#define CONNECTIONPOOL_TEST
constexpr int TEST_NUM = 5000;

int main()
{
    string sql = "INSERT INTO test_users (username, email, age) VALUES ('zhangsan', 'user@example.com', 25)";
    //clock_t start = clock();
    auto start = std::chrono::steady_clock::now();

#ifndef CONNECTIONPOOL_TEST
    for (int i = 0; i < TEST_NUM; ++i)
    {
        Connection conn;
        conn.connect("127.0.0.1", 3306, "root", "123456", "test");
        conn.update(sql);
    }
#else
    ConnectionPool *pool = ConnectionPool::getConnectionPool();
    for (int i = 0; i < TEST_NUM; ++i)
    {
        auto conn = pool->getConnection();
        conn->update(sql);
    }
#endif


    //clock_t end = clock();
    //double elapsed = (double)(end - start) / CLOCKS_PER_SEC;
    auto end = std::chrono::steady_clock::now(); 
    auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
    
    // 格式化输出（毫秒）
    //printf("执行时间: %.0f 毫秒\n", elapsed * 1000);
    printf("数量: %d, 执行时间: %ld 毫秒\n", TEST_NUM, ms);


    return 0;
}